package com.example.mq.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;

import java.util.Date;

/*
 * @className: SysMqReceiveLog
 * @author: chentao
 * @date: 2025/3/28 上午8:12
 * @Version: 1.0
 * @description: mq接收记录
 */
@Data
@TableName(value = "sys_mq_receive_log")
public class SysMqReceiveLog extends Model<SysMqReceiveLog> {

    @TableId(type = IdType.AUTO)
    private Long id;

    //处理工厂
    @TableField(value = "factory_name")
    private String factoryName;

    //交换机
    @TableField(value = "exchange_name")
    private String exchangeName;

    //队列名称
    @TableField(value = "queue_name")
    private String queueName;

    //路由key
    @TableField(value = "routing_key")
    private String routingKey;

    //处理bean
    @TableField(value = "bean_name")
    private String beanName;

    //接收节点id
    @TableField(value = "server_id")
    private Long serverId;

    //消息内容
    @TableField(value = "context")
    private String context;

    //状态
    @TableField(value = "status")
    private boolean status;

    //创建时间
    @TableField(value = "create_time")
    private Date createTime;

    //更新时间
    @TableField(value = "update_time")
    private Date updateTime;

    public SysMqReceiveLog(String factoryName, String exchangeName, String queueName, String routingKey, String beanName, Long serverId, String context) {
        this.factoryName = factoryName;
        this.exchangeName = exchangeName;
        this.queueName = queueName;
        this.routingKey = routingKey;
        this.beanName = beanName;
        this.serverId = serverId;
        this.context = context;
        this.status = true;
    }

    public SysMqReceiveLog(String factoryName, String queueName, String beanName, Long serverId, String context) {
        this.factoryName = factoryName;
        this.queueName = queueName;
        this.beanName = beanName;
        this.serverId = serverId;
        this.context = context;
        this.status = true;
    }

    public void recalculateFields() {
        if (this.createTime == null) {
            this.createTime = new Date();
        }
        this.updateTime = new Date();
    }
}
